package com.benyi.util;

import java.util.Arrays; 
import java.util.List;

public class SplitUtil {
	
	public static String[] split(String sentence) {
        if (sentence == null || sentence.isEmpty()) {
            return null;
        } 
        String trimmed = sentence.replaceAll("^[\u3000 ]+|[\u3000 ]+$", ""); // 去除首尾的中英文空格
        if (trimmed.isEmpty()) {
            return null;
        } 
        String[] words = trimmed.split("[\u3000 .,?%#@!()-:;，：；？、'\"<>]+"); // 按中英文空格分割
        List<String> ls =  Arrays.asList(words);
        String []as = new String[ls.size()];
        for(int i=0;i<ls.size();i++) {
        	as[i] = ls.get(i);
        }
        return as;
    }
	
	public static void main(String[] args) {
        String test1 = "hello,world;你好";
        String test2 = "hello；world？　你好"; // 中文空格分隔
        String test3 = "　, .>< 测试  ";       // 首尾混合空格
        String test4 = "   ";              // 全英文空格
        String test5 = "混合 空格　测试";    // 混合空格

        System.out.println(Tools.toString(split(test1),",")); // [hello, world, 你好]
        System.out.println(Tools.toString(split(test2),",")); // [hello, world, 你好]
        System.out.println(Tools.toString(split(test3),",")); // [测试]
        System.out.println(Tools.toString(split(test4),",")); // []
        System.out.println(Tools.toString(split(test5),",")); // [混合, 空格, 测试]
    }
}
